{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">
                            <div class="layui-input-inline">
                                <input type="text"  name="start" onfocus="wk.lay_date(this);"  class="layui-input layer-date search" placeholder="上次登录开始日期" />
                            </div>
                            <div class="layui-input-inline">
                                <input type="text"  name="end" onfocus="wk.lay_date(this);"  class="layui-input layer-date search" placeholder="上次登录结束日期" />
                            </div>
                            <div class="layui-input-inline layui-form">
                                <select name="role" id="role" lay-search="" class="layui-input">
                                    <option  value="">不限角色</option>
                                    {foreach name="role" item="vo"}
                                        <option  value="{$vo.id}">{$vo.title}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <div class="layui-col-md6 layui-input-inline">
                                <input type="text" id="key" class="layui-input search" name="key" value="" placeholder="用户名/真实姓名"/>
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                                <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                            </div>
                        </div>
                </div>
                <!--搜索框结束-->
                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group" >
                        <button class="btn btn-primary" type="button" onclick="wk.href('{:url('userAdd')}');">
                            <i class="fa fa-plus"></i> 添加管理员
                        </button>
                        <button  class="btn btn-danger m-l-xs" href="javascript:;" data-toggle="dropdown">
                            <i class="fa fa-wrench"></i> 批量操作 <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu layui-anim layui-anim-upbit" role="menu">
                            <li><a href="javascript:;" class="layuiBtn" data-type="getCheckData"><i class="fa fa-trash-o"></i> 批量删除 </a></li>
                            <li><a  href="javascript:;" class="layuiBtn" data-type="usingAll"><i class="fa fa-check-circle"></i> 批量启用</a></li>
                            <li><a  href="javascript:;" class="layuiBtn" data-type="forbiddenAll"><i class="fa fa-ban"></i> 批量禁用</a></li>
                            <li><a  href="javascript:;" class="layuiBtn" data-type="excelAll"><i class="fa fa-print"></i> 导出Excel</a></li>
                        </ul>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <!--图片模板-->
                    <script type="text/html" id="imgTpl">
                        <img src="{{d.portrait}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"  />
                    </script>
                    <!--角色模板-->
                    <script type="text/html" id="titleTpl">
                        {{# if(d.title == null){ }}
                            <span style="color:#ec4758">重新分配角色</span>
                        {{# }else{ }}
                            {{d.title}}
                        {{# } }}
                    </script>
                    <!--状态模板-->
                    <script type="text/html" id="staBar">
                        {{# if(d.id!==1){ }}
                            <input type="checkbox" value="{{d.id}}"  lay-skin="switch"  lay-text="启用|禁用" lay-filter="OnOff"{{ d.status == 1 ? 'checked' : '' }}  >
                        {{# } }}
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        {{# if(d.id!==1){ }}
                            <a href="javascript:;" onclick="wk.href('{:url('userEdit')}?id={{d.id}}')" class="btn btn-primary btn-xs m-r-xs" title="编辑"><i class="fa fa-pencil"></i></a>
                            <a href="javascript:;" onclick="wk.confirm('{{d.id}}','{:url('userDel')}')" class="btn btn-danger btn-xs m-r-xs" title="删除"><i class="fa fa-trash-o"></i></a>
                            {{# }else{ }}
                            <a href="javascript:;" onclick="wk.href('{:url('userEdit')}?id={{d.id}}')" class="btn btn-primary btn-xs m-r-xs" title="编辑"><i class="fa fa-pencil"></i></a>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
        , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("User/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type: 'checkbox', fixed: 'left',}
                , {type:'numbers', width: 80, title: '序号'}
                , {field: 'username', width: '', title: '管理员名称', align: 'center'}
                , {field: 'portrait', width: 90, title: '头像', align: 'center', templet: '#imgTpl'}
                , {field: 'title', width: '', title: '管理员角色', align: 'center', templet: '#titleTpl'}
                , {field: 'loginnum', width: '', title: '登录次数', sort: true, align: 'center'}
                , {field: 'last_login_ip', width: '', title: '上次登录IP', align: 'center'}
                , {field: 'last_login_time', width: '', title: '上次登录时间', sort: true, align: 'center',templet:"<div>{{d.last_login_time?layui.util.toDateString(d.last_login_time*1000,'yyyy-MM-dd HH:MM'):''}}</div>"}
                , {field: 'phone', width: '', title: '联系方式', align: 'center'}
                , {field: 'real_name', width: '', title: '真实姓名', align: 'center'}
                , {field: 'status',fixed: 'right', width: 100, title: '状态',sort: true, align: 'center', templet: '#staBar'}
                , {fixed: 'right', width: 100, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.img-circle').viewer({
                    url: 'data-original',
                });
            }
        });
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //用户状态
            wk.status(this.value,num, '{:url("user_state")}',obj);
        });

        //批量操作
        var $ = layui.$, active = {
            getCheckData: function(){
                //批量删除
                wk.batchDel(getIds(),"{:url('batchDelUser')}");
            }
            ,forbiddenAll: function(){
                //批量禁用
                wk.batchForbidden(getIds(),2,"{:url('forbiddenAdmin')}");
            }
            ,usingAll: function(){
                //批量启用
                wk.usingAll(getIds(),1,"{:url('usingAdmin')}");
            }
            ,excelAll: function(){
                //导出Excel
                wk.excelAll(getIds(),$('.layui-input').serialize(),"{:url('excelAdmin')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>